<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"/>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib"%>
       <div>
         <input type="hidden" name="projectId" value="${projectId}" id="projectId"/> 	       
         <div id="mydialog"></div>
         <div id="mydialog2"></div>            
       </div>
	    <script type="text/javascript">
	     var projectId=$("#projectId").val();
	     var professorId
	     var arr
	    $(function(){   
	         $('#mydialog').datagrid({
	                     idField:'id',
	                     width:1000,
	                     height:345,
                         url:'${ctx}/business/professor/professorInfoList?projectId='+projectId,      
	                    // fitColumns:true,//自动填充宽度
	                     striped:true,//隔行变色
	                     loadMsg:"数据正在加载中.....",
	                     rownumbers:true,//显示序号
	                     singleSelect:false,
	                     pagination:true,	
	                     nowrap:false, 
	                     cache: false,    
	                     pageSize:5,
	                     pageList:[10,15,20],
	                     columns:[[   
	                     { field:'ck',checkbox:true }, 
				         {field:'name',title:'专家名称',width:150,align:'center'}, 
				         {field:'deptName',title:'单位',width:250,align:'center'}, 
				         {field:'tel',title:'联系方式',width:230,align:'center'},
				         {field:'title',title:'职称',width:150,align:'center'}, 
				         {field:'type',title:'人员类型',width:150,align:'center',formatter:professortype},         
			            ]],
			         toolbar:[
			                {text:'录入',iconCls:'icon-add',handler:function(){  			                    
                                      saveprofessorInfo();
                                }  
                            },  
                             
                            {text:'修改',iconCls:'icon-edit',handler:function(){  
                                      editProfessor();
			                    }  
			                },  
                           {text:'删除',iconCls:'icon-remove',handler:function(){  
                                       deleteProfessor();
                                }  
                           }
                       ]     
			        });
		 });
		 
		 /**录入专家信息*/
		   function saveprofessorInfo(){
                  $('#secondtLevelDialog').dialog({
                    title:"专家信息录入",  
				    iconCls:'icon-role-menu',
				    width:400,    
				    height: 300,    
				    closed:false,    
				    cache: false,    
				    href: '${ctx}/business/professor/toAddProfessorPage?projectId='+projectId,
				    modal: true,
				    buttons : [{text:'确定',
				    id:'saveEntityBt',
					iconCls : 'icon-ok',
					handler : function(){
					               if (!$('#addprofessorDataForm').form('validate')) {
										$.messager.alert('提示信息','信息输入不完整，请完善专家信息!','info');
										return false;
										}
							      $.ajax({
							         url:'${ctx}/business/professor/saveProfessorInfo',
							         data:$("#addprofessorDataForm").serialize(),
							         cache:false,
							         type:'post',
							         success:function(data){
										   top.$.messager.alert('提示信息','信息保存成功!','info');	
							               $('#secondtLevelDialog').dialog('close');
							               $('#mydialog').datagrid('reload');
							              
							         }
							      });	
									},
						
				         },
							{
								text : '取消',
								iconCls : 'icon-cancel',
								handler : function() {
									$('#secondtLevelDialog').dialog('close');
								}
							} ]
							});
						}
						

						
					function editProfessor(){	
						 arr = $("#mydialog").datagrid('getSelections');
						  if(arr.length !=1){
						    /* $.messager.show({
						        title:"提示信息",
						        msg:"请选择一条记录进行修改!"				        
						     });*/
						     top.$.messager.alert('提示信息','请选择一条记录进行修改!','info');		
						     }else
						       {
								 professorId=arr[0].id;
								 eidtprofessorInfo(professorId);															
						     }					  
						}
					
					
			 /**修改专家信息*/			
			function eidtprofessorInfo(professorId){
				 $('#secondtLevelDialog').dialog({
	                    title:"专家信息修改",  
					    iconCls:'icon-role-menu',
					    width:400,    
					    height: 300,    
					    closed:false,    
					    cache: false,    
					     href: '${ctx}/business/professor/toEditProfessorPage?professorId='+professorId,
					    modal: true,
					    buttons : [{text:'确定',
					    id:'saveEntityBt',
						iconCls : 'icon-ok',
						handler : function(){
						              if (!$('#addprofessorDataForm').form('validate')) {
									/*	$.messager.show({
											title : '提示信息',
											msg : '验证没有通过,不能提交表单!',
											timeout:5000
										});*/
										top.$.messager.alert('提示信息','验证没有通过,不能提交表单','info');			
										return false;
										}
							      $.ajax({
							         url:'${ctx}/business/professor/saveProfessorInfo',
							         data:$("#addprofessorDataForm").serialize(),
							         type:'post',
							         success:function(data){
							            /*   $.messager.show({
												title : '提示信息',
												msg : '信息保存成功！'
												});*/
												top.$.messager.alert('提示信息','信息保存成功!','info');				
							               $('#secondtLevelDialog').dialog('close');
							               $('#mydialog').datagrid('reload');
							               $('#mydialog').datagrid('clearSelections');							           
							         }
							      });	
										},
							
					         },
								{
									text : '取消',
									iconCls : 'icon-cancel',
									handler : function() {
										$('#secondtLevelDialog').dialog('close');
									$('#mydialog').datagrid('clearSelections');	
									}
								} ]
								}).dialog('open');;
			}
						
				/**删除专家信息**/		
				function  deleteProfessor(){
				     var arr = $("#mydialog").datagrid('getSelections');
				 	var professorId = '';
					for(var i=0;i<arr.length;i++){
						professorId += arr[i].id+",";
					}
						  if(arr.length <1){
							  $.messager.alert('提示信息','请选择一条记录!','info');		
						    /* $.messager.show({
						        title:"提示信息",
						        msg:"请选择一条记录进行修改!"						               
						     });	*/					
						     }else
						       {
								 $.ajax({
								    type:'post',
							        url:'${ctx}/business/professor/deleteProfessorInfo',
							        data:{professorId:professorId},
							        success:function(data){
							        if(data="delSuccess"){
							        	top.$.messager.alert('提示信息','删除成功!','info');		
								       /*  $.messager.show({
										        title:"提示信息",
										        msg:"删除成功!"				        
							                });*/
							              $('#mydialog').datagrid('reload');   
							              $('#mydialog').datagrid('clearSelections');	
							        }else{
							        	top.$.messager.alert('提示信息','删除失败!','info');		
							          /*   $.messager.show({
										        title:"提示信息",
										        msg:"删除失败!"				        
							                });*/
							        }
							           
							        }
								 });															
						     }					  
				  }
				
				function professortype(val, row, index) {
					if (row.type  == 1) {
						return "专家";
					} else if (row.type == 2) {
						return "监督员";
					} else if (row.type == 3) {
						return "业主";
					}
				}

       </script>

                 
   
  
